/**
* @file app_sensor.c in InsCubeBsp
* @author linfe
* @comment
* Create on 2023/2/1 0:00
* @version 1.0
**/

#include "app_sensor.h"
#include "app_trace.h"
#include "main.h"
#if APP_CONFIG_IMU == 0

#define IMU_CONFIG \
{                                           \
.config = {                                 \
    .sample_rate = 100,                     \
    .acce_full_scale = ICM20602AcceFs_2G,   \
    .gyro_full_scale = ICM20602GyroFs_2000DEG,  ]\
},                                                \
.data_ready_pin = ICM_INT_0_Pin,                    \
.dev = spi1_dev,   \
};


#define IMU_INIT_FUNC icm2060x_init
#define IMU_READ_FUNC icm2060x_read

#elif APP_CONFIG_IMU == 1
#define IMU_CONFIG                  \
{                                   \
.dev = spi5_dev,                    \
.data_ready_pin = ADI_INT_Pin,      \
.rate_div = 0XF,                    \
.trace  = common_trace,             \
.delay_ms = bsp_delay_ms,           \
}
#define IMU_INIT_FUNC adis1646x_init
#define IMU_READ_FUNC adis1646x_read
#endif

imu_error_t imu_init(imu_sensor_act_t *sensor_act){
    imu_handle_t imu_handle = {
        .config = {
            .sample_rate = ICM20602SampleRate_1000Hz,
            .acce_full_scale = ICM20602AcceFs_2G,
            .gyro_full_scale = ICM20602GyroFs_2000DEG,
        },
        .data_ready_pin = ICM_INT_0_Pin,
        .dev = &spi1_dev,
        .trace  = common_trace,
        .delay_ms = bsp_delay_ms,
    };
    sensor_act->imu_handle = imu_handle;
    sensor_act->init_func = IMU_INIT_FUNC;
    sensor_act->imu_read = IMU_READ_FUNC;
    return sensor_act->init_func(&sensor_act->imu_handle);
}

imu_error_t imu_read(imu_sensor_act_t *sensor_act, imu_raw_t* data){
    return sensor_act->imu_read(&sensor_act->imu_handle,data);
}

imu_sensor_act_t imu_sensor_act = {
    .imu_handle = {},
    .init_func = NULL,
    .imu_read = NULL
};